<template>
  <div id="app">
    <router-view></router-view>

    <!-- 底部导航 -->
    <div class="tabbar">
      <router-link
              v-for="tab in tabs"
              :key="tab.name"
              :to="tab.path"
              class="tab-item"
              :class="{ active: $route.path === tab.path }"
      >
        <img :src="$route.path === tab.path ? tab.iconActive : tab.icon" alt="">
        <span>{{ tab.label }}</span>
      </router-link>
    </div>
  </div>
</template>

<script>
    import homeIcon from '@/assets/icons/home0.png'
    import homeIconActive from '@/assets/icons/home1.png'
    import courseIcon from '@/assets/icons/manage0.png'
    import courseIconActive from '@/assets/icons/manage1.png'
    import profileIcon from '@/assets/icons/user0.png'
    import profileIconActive from '@/assets/icons/user1.png'
    export default {
        name: 'App',
        data() {
            return {
                tabs: [
                    {
                        name: '首页',
                        label: '首页',
                        path: '/home',
                        icon: homeIcon,
                        iconActive: homeIconActive
                    },
                    {
                        name: '课程管理',
                        label: '课程管理',
                        path: '/course',
                        icon: courseIcon,
                        iconActive: courseIconActive
                    },
                    {
                        name: '个人中心',
                        label: '个人中心',
                        path: '/profile',
                        icon: profileIcon,
                        iconActive: profileIconActive
                    }
                ]
            };
        },
        mounted() {
            const redirect = this.$route.query.redirect;
            if (redirect) {
                const decoded = decodeURIComponent(redirect);
                this.$router.replace(decoded);
            }
        }
    };
</script>

<style>
  /* 底部导航样式 */
  #app {
    min-height: 100vh;
    padding-bottom: 60px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  }
  .tabbar {
    display: flex;
    border-top: 1px solid #f0f0f0;
    background: #fff;
    height: 80px;
    position: fixed;
    bottom: 0;
    width: 100%;
  }
  .tab-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: #666;
    text-decoration: none;
  }
  .tab-item.active {
    color: #1890ff;
  }
  .tab-item img {
    width: 20px;
    height: 20px;
    margin-bottom: 2px;
  }
</style>
